// script.js
const suits = ['♠', '♥', '♦', '♣'];
const values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '小王', '大王'];

let deck = [];
let players = [[], [], []]; // 3个玩家
let landlordCards = [];

function createDeck() {
    deck = [];
    for (let suit of suits) {
        for (let value of values) {
            deck.push(value + suit);
        }
    }
    deck.push('小王', '大王'); // 加入大小王
    shuffleDeck();
}

function shuffleDeck() {
    for (let i = deck.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [deck[i], deck[j]] = [deck[j], deck[i]];
    }
}

function dealCards() {
    for (let i = 0; i < 17; i++) {
        for (let j = 0; j < 3; j++) {
            players[j].push(deck.pop());
        }
    }
    landlordCards = [deck.pop(), deck.pop(), deck.pop()]; // 地主的底牌
}

function displayHands() {
    for (let i = 0; i < players.length; i++) {
        const handDiv = document.getElementById(`hand${i + 1}`);
        handDiv.innerHTML = players[i].map(card => `<div class="card">${card}</div>`).join('');
    }
    const landlordDiv = document.getElementById('hand_landlord');
    landlordDiv.innerHTML = landlordCards.map(card => `<div class="card">${card}</div>`).join('');
}

document.getElementById('startBtn').addEventListener('click', () => {
    createDeck();
    dealCards();
    displayHands();
    document.getElementById('message').innerText = "游戏开始！";
});
